package io.renren.modules.course.service.impl;

import io.renren.modules.course.dao.CourseSmallDao;
import io.renren.modules.course.entity.CourseSmallClassification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.course.dao.ClassificationDao;
import io.renren.modules.course.entity.ClassificationEntity;
import io.renren.modules.course.service.ClassificationService;


@Service("classificationService")
public class ClassificationServiceImpl extends ServiceImpl<ClassificationDao, ClassificationEntity> implements ClassificationService {

@Autowired
CourseSmallDao courseSmallDao;


    @Override
    public void online(Map map) {
        courseSmallDao.online(map);
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        PageUtils pageUtils = null;
        if(params.size()!=0) {
            //总数
            int totalCount = baseMapper.selectClassCount();
            //当前页码
            int page = Integer.parseInt((String) params.get("page"));
            //每页显示数
            int pageSize = Integer.parseInt((String) params.get("limit"));
            //页数
            int totalPage = (totalCount + pageSize - 1) / pageSize;
            //当前页数第一条
            int start = pageSize * (page - 1);

            params.put("start", start);
            params.put("end", page * pageSize);

            List<ClassificationEntity> list = baseMapper.selectClassList(params);

            pageUtils = new PageUtils(list, totalCount, pageSize, page);
        }else{
            List<ClassificationEntity> list = baseMapper.selectAllClassList();
            int totalCount = baseMapper.selectClassCount();
            pageUtils = new PageUtils(list, totalCount, 1000, 1);
        }
        return pageUtils;
    }


}
